<%@ Page Language="C#" AutoEventWireup="true" CodeFile="reservation.aspx.cs" Inherits="pages_admin_reservation" MasterPageFile="~/template/template.master"%>

<%@ Register Namespace="UTS.Controls" TagPrefix="uts" %>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="ReservationDisplayPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
        <asp:Panel ID="ReservationViewPanel" runat="server">
            <uts:SemesterDropDownList ID="SemesterListDropDown" runat="server" DataTextField="SemesterName" DataValueField="SemesterId" />
    
            <asp:GridView ID="ReservationGridView" runat="server" 
                    AutoGenerateColumns="false"
                    CssClass="gridview"
                    onrowcreated="ReservationGridView_RowCreated" > 
                    
                <Columns>
                    <asp:TemplateField HeaderText="Cohort">
                        <ItemTemplate>
                            <asp:Literal ID="Cohort" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Module">
                        <ItemTemplate>
                            <asp:Literal ID="Module" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>        
                    <asp:TemplateField HeaderText="Module Events">
                        <ItemTemplate>
                            <asp:Literal ID="ModuleEventInfo" runat="server" />                            
                        </ItemTemplate>
                    </asp:TemplateField>                        
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="Edit" runat="server" OnClick="ReservationEdit" Text="Edit" CommandArgument='<%# Eval("ReservationViewId") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>                                        
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="Delete" runat="server" OnClick="ReservationDelete" Text="Delete" CommandArgument='<%# Eval("ReservationViewId") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>                                                        
                </Columns>
            </asp:GridView>

            <asp:LinkButton ID="New" runat="server" OnClick="ReservationNew" Text="New" />
        </asp:Panel>
        
        <asp:Panel ID="ReservationEditingPanel" runat="server" Visible="false">
            Edit
            <asp:DetailsView ID="ReservationDetailsView" CssClass="detailstable" FieldHeaderStyle-CssClass="bold" runat="server" AutoGenerateRows="false" DefaultMode="Edit" OnDataBound="ReservationDetailsView_DataBound">
                <Fields>
                    <asp:TemplateField HeaderText="Semester">
                        <EditItemTemplate>
                            <uts:SemesterDropDownList ID="Reservation_SemesterDropDownList" runat="server" DataTextField="SemesterName" DataValueField="SemesterId"/>    
                        </EditItemTemplate>
                    </asp:TemplateField>        
                    <asp:TemplateField HeaderText="Cohort">
                        <EditItemTemplate>
                            <uts:CohortDropDownList ID="Reservation_CohortDropDownList" runat="server" AutoPostBack="true" DataTextField="CohortName" DataValueField="CohortId"
                                                    OnSelectedIndexChanged="Reservation_CohortDropDownList_SelectedIndexChanged"/>    
                        </EditItemTemplate>
                    </asp:TemplateField>        
                    <asp:TemplateField HeaderText="Module">
                        <EditItemTemplate>
                           <uts:ModuleDropDownList 
                                    ID="Reservation_ModuleDropDownList" 
                                    runat="server" 
                                    AutoPostBack="true"
                                    DataTextField="ModuleName" 
                                    DataValueField="ModuleId"
                                    OnSelectedIndexChanged="Reservation_ModuleDropDownList_SelectedIndexChanged"/>    
                        </EditItemTemplate>
                    </asp:TemplateField>                                
                    <asp:TemplateField HeaderText="Lecturer">
                        <EditItemTemplate>
                            <uts:LecturerDropDownList 
                                    ID="Reservation_LecturerDropDownList" 
                                    runat="server" 
                                    AutoPostBack="true"
                                    DataTextField="LecturerName" 
                                    DataValueField="LecturerId" />
                        </EditItemTemplate>
                    </asp:TemplateField>                   
                    <asp:TemplateField HeaderText="Reservations">
                        <EditItemTemplate>
                            <table>
                                <tr>
                                    <td></td>
                                    <td>
                                        Class Event
                                    </td>
                                    <td>
                                        Start Time    
                                    </td>
                                    <td>
                                        End Time
                                    </td>
                                </tr>
                                <tr>
                                <td colspan="2">
                                <asp:Repeater ID="ClassEventRepeater" runat="server" OnItemCreated="ClassEventRepeater_ItemCreated">
                                    <ItemTemplate>
                                        <tr>
                                            <td>
                                                <asp:HiddenField ID="ClassEventId" runat="server" Value='<%# Eval ("TimetableEventId") %>' />
                                                <asp:Literal ID="HiddenField1" runat="server" text='<%# Eval ("TimetableEventId") %>' Visible="false"/>
                                            </td>
                                            <td>
                                                <asp:HiddenField ID="ClassEventTypeId" runat="server"  Visible="true"/>
                                                <asp:CheckBox ID="ClassEventReserved" runat="server"/>
                                            </td>                                
                                            <td>
                                                <asp:Literal ID="ClassEventTypeNameLiteral" runat="server"/>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="ClassEventStartTimeTextbox" runat="server" />
                                            </td>
                                            <td>
                                                <asp:TextBox ID="ClassEventStopTimeTextbox" runat="server" />
                                            </td>                                    
                                            <td>
                                                <uts:CourseDayDropDownList ID="CourseDayDropDownList" runat="server" DataTextField="CourseDayName" DataValueField="CourseDayId" AutoPostBack="false"/>
                                            </td>                                                                                                            
                                            <td>
                                                <uts:RoomDropDownList ID="ClassEventRoomDropDown" runat="server" DataTextField="RoomName" DataValueField="RoomId"/>
                                            </td>                                                                        
                                        </tr>                            
                                    </ItemTemplate>
                                </asp:Repeater>
                                
                                
                                </td>
                                </tr>
                                
                            </table>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Fields>
                <FooterTemplate>
                       <asp:Button ID="SaveReservation" runat="server" OnClick="SaveReservations" text="Save"/>
                       <asp:Button ID="BackButton" runat="server" text="Back" OnClick="BackButton_Click" />
                </FooterTemplate>
            </asp:DetailsView>
        </asp:Panel>           
           
</ContentTemplate>
</asp:UpdatePanel>        
</asp:Content>